<template>
	<view>
		<u-row customStyle="margin-bottom: 80px">
			<u-col span="12">
				<view>
					<u-navbar
					    title="教育经历"
						titleStyle="font-weight:bold"
					    :safeAreaInsetTop="true"
						:fixed='true'
						bgColor="#FFBE59"
						@leftClick="leftClick"
						@rightClick="delIntention"
					>
					    <view
					        class="u-nav-slot"
					        slot="left"
							
					    >
					        <u-icon
					            name="arrow-left"
					            size="20"
								color="black"
					        ></u-icon>
					    </view>
						<view
						    class="u-nav-slot"
						    slot="right"
						>
						    <u-icon
								v-if="this.eduId!=''"
						        name="trash"
						        size="22"
								color="black"
						    ></u-icon>
						</view>
					</u-navbar>
				</view>
			</u-col>
		</u-row>
		<u-modal :show="showConfirm" @confirm="confirmFunction()" @cancel="cancelFunction()" width="250px" :content='contentConfirm' :showCancelButton='true'></u-modal>
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="12" style="margin: 0 auto;">
				<view class="resume bg-purple-light">
					<u-col span="11" style="margin: 0 auto;">
						<view class="schoolName bg-purple-light">
							<p>学校名称</p>
							 <u--input
							    placeholder="请输入学校全称"
							    border="bottom"
							    v-model="SchoolNameValue"
							  ></u--input>
						</view>
					</u-col>
					<u-col span="11" style="margin: 0 auto;">
						<view class="major bg-purple-light">
							<p>所学专业</p>
							 <u--input
							    placeholder="请输入所学专业"
							    border="bottom"
							    v-model="majorValue"
							  ></u--input>
						</view>
					</u-col>
					<u-col span="11"  style="margin: 0 auto;">
						<view class="name-title bg-purple-light" @click="showEducation = true">
							<span>学历</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p>{{this.educationValue}}</p>
							<u-picker :show="showEducation" :columns="educationColumns"  @confirm="educationConfirm" @cancel="educationCancel"></u-picker>
						</view>
					</u-col>
					<u-col span="11"  style="margin: 0 auto;">
						<view class="name-title bg-purple-light" @click="showUnifiedRecruitment = true">
							<span>是否统招</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p>{{this.unifiedRecruitmentValue}}</p>
							<u-picker :show="showUnifiedRecruitment" :columns="unifiedRecruitmentColumns"  @confirm="unifiedRecruitmentConfirm" @cancel="unifiedRecruitmentCancel"></u-picker>
						</view>
					</u-col>
					<u-col span="11" style="margin: 0 auto;">
						<view class="name-title bg-purple-light" @click="showDateOfAdmission=true">
							<span>入学日期</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p><uni-dateformat :date="this.dateOfAdmissionValue" format='yyyy/MM/dd'></uni-dateformat></p>
							<u-datetime-picker
								:show="showDateOfAdmission"
								v-model="dateOfAdmissionValue"
								mode="date"
								:minDate="1980"
								@confirm="dateOfAdmissionConfirm"
								@cancel="dateOfAdmissionCancel"
							></u-datetime-picker>
						</view>
					</u-col>
					<u-col span="11" style="margin: 0 auto;">
						<view class="name-title bg-purple-light" @click="showGraduationDate=true">
							<span>毕业日期</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p><uni-dateformat :date="this.graduationDateValue" format='yyyy/MM/dd'></uni-dateformat></p>
							<u-datetime-picker
								:show="showGraduationDate"
								v-model="graduationDateValue"
								mode="date"
								:minDate="1980"
								@confirm="graduationDateConfirm"
								@cancel="graduationDateCancel"
							></u-datetime-picker>
						</view>
					</u-col>
					<u-col span="11" style="margin: 0 auto;">
						<view class="keep-button bg-purple-light">
							<u-button type="primary" text="保存" @click="subEdu()"></u-button>
						</view>
					</u-col>
				</view>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				majorValue:"",
				showGraduationDate: false,
				graduationDateValue:"",
				showDateOfAdmission: false,
				dateOfAdmissionValue: "",
				SchoolNameValue: '',
				educationValue:'',
				unifiedRecruitmentValue:'',
				showEducation: false,
				educationColumns: [
					['初中及以下','高中','中专/中技','大专', '本科','博士','硕士']
				],
				showUnifiedRecruitment: false,
				unifiedRecruitmentColumns: [
					['统招', '非统招']
				],
				edu:{},
				eduId:"",
				resumeId:"",
				eduUrl:'',
				showConfirm:false,
				contentConfirm:'',
			}
		},
		created() {
			//编辑回显
			if(this.eduId!=""){
				this.$axios.get('/resume/employmentResume/queryEducationExperienceById?id='+this.eduId).then((res)=>{
					if(res.data.result){
						this.edu = res.data.result;
						this.SchoolNameValue = this.edu.schoolName;
						this.majorValue = this.edu.schoolMajor;
						this.educationValue = this.educationColumns[0][this.edu.educationId];
						this.unifiedRecruitmentValue = this.unifiedRecruitmentColumns[0][this.edu.recruitment];
						this.dateOfAdmissionValue = this.edu.schoolIntime;
						this.graduationDateValue = this.edu.schoolOuttime;
					}
				});
			}
		},
		methods: {
			//左侧点击返回上一页面
			leftClick(){
				uni.reLaunch({
					url: '/pages/service/practicaltrainingservice/resume/resume',
				});
			},
			//删除的对话窗
			delIntention(){
				this.showConfirm = true;
				this.contentConfirm = "确认要删除吗？";
			},
			confirmFunction(){//确认按钮
				this.$axios.get('/resume/employmentResume/delEducationExperienceById?id='+this.edu.id).then((res)=>{
					if(res.data.success){//true
						uni.redirectTo({
							url: '/pages/service/practicaltrainingservice/resume/resume',
						});
					}else{
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '删除失败'
						});
					}
				});
			},
			cancelFunction(){//取消按钮
				this.showConfirm = false;
			},
			//保存
			subEdu(){
				var flag = true;
				if(this.SchoolNameValue==""||this.SchoolNameValue==undefined){
					flag = false;
				}
				if(this.majorValue==""||this.majorValue==undefined){
					flag = false;
				}
				if(this.educationValue==""||this.educationValue==undefined){
					flag = false;
				}
				if(this.unifiedRecruitmentValue==""||this.unifiedRecruitmentValue==undefined){
					flag = false;
				}
				if(this.dateOfAdmissionValue==""||this.dateOfAdmissionValue==undefined){
					flag = false;
				}
				if(this.graduationDateValue==""||this.graduationDateValue==undefined){
					flag = false;
				}
				if(flag==true){//所有表单都已填写
				//判断入学日期和毕业日期是否正确
				if(this.dateOfAdmissionValue>this.graduationDateValue||this.graduationDateValue==this.dateOfAdmissionValue){
					uni.showToast({
						icon: 'error',
						position: 'bottom',
						title: '日期选择有误'
					});
					window.eval(flag);//指定执行指定代码	（var flag=true）
					return ;
				}
					this.edu.resumeId = this.resumeId;
					this.edu.schoolName = this.SchoolNameValue;
					this.edu.schoolMajor = this.majorValue;
					//学历
					for (var i = 0; i < this.educationColumns[0].length; i++) {
						if(this.educationColumns[0][i]==this.educationValue){
							this.edu.educationId = i;
						}
					}
					//是否统招
					for (var i = 0; i < this.unifiedRecruitmentColumns[0].length; i++) {
						if(this.unifiedRecruitmentColumns[0][i]==this.unifiedRecruitmentValue){
							this.edu.recruitment = i;
						}
					}
					/* this.edu.schoolIntime = uni.$u.timeFormat(this.dateOfAdmissionValue, 'yyyy/mm/dd');
					this.edu.schoolOuttime = uni.$u.timeFormat(this.graduationDateValue, 'yyyy/mm/dd'); */
					this.edu.schoolIntime = this.dateOfAdmissionValue;
					this.edu.schoolOuttime = this.graduationDateValue;
					//通过教育经历编号是否为空判断是新增还是修改
					if(this.eduId!=""){//修改
						this.eduUrl = "/resume/employmentResume/upEducationExperience";
					}else{//新增
						this.eduUrl = "/resume/employmentResume/addEducationExperience";
					}
					this.$axios.post(this.eduUrl,this.edu).then((res)=>{
						if(res.data.success){//true
							uni.redirectTo({
								url: '/pages/service/practicaltrainingservice/resume/resume',
							});
						}else{
							uni.showToast({
								icon: 'error',
								position: 'bottom',
								title: '操作失败'
							});
						}
					});
				}else{
					uni.showToast({
						icon: 'error',
						position: 'bottom',
						title: '信息填写不完整'
					});
				}
			},
			graduationDateConfirm(e) {
				this.showGraduationDate = false;
			},
			graduationDateCancel(){
				this.showGraduationDate = false;
			},
			dateOfAdmissionConfirm(e) {
				this.showDateOfAdmission = false;
			},
			dateOfAdmissionCancel(){
				this.showDateOfAdmission = false;
			},
			educationConfirm(e) {
				this.educationValue = e.value[0];
				this.showEducation = false;
			},
			educationCancel(){
				this.showEducation = false;
			},
			unifiedRecruitmentConfirm(e) {
				this.unifiedRecruitmentValue = e.value[0];
				this.showUnifiedRecruitment = false;
			},
			unifiedRecruitmentCancel(){
				this.showUnifiedRecruitment = false;
			},
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			this.eduId = option.eduId;//教育经历编号
			this.resumeId = option.resumeId;//简历编号
		}
	}
</script>

<style lang="less">
	.schoolName p,.major p{font-size: 14px;color: #3C3C3C;}
	.name-title,.schoolName,.major{height: 56px;margin-top: 20px;}
	.name-title{border-bottom: 0.1px solid #E5E4E2;}
	.name-title p{font-size: 14px;color: #3C3C3C;margin-top: 12px;margin-left:2px;font-size: 14px;font-weight: bold;}
	span{font-size: 14px;color: #3C3C3C;}
	.name-title-icon{float: right;margin-top: 10px;}
	.keep-button{margin-top: 20px;}
</style>